package system;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.JTextField;



public class Login extends JPanel{
	
	
	private static final long serialVersionUID = 1L;
	public JTextField usernametext;
	public JPasswordField passwordfield;
	public JButton login;
	public JButton cancel;
	public JLabel brukernavn;
	public JLabel passord;
	public JLabel space;
	public JLabel top;
	public ImageIcon icon;
	
	
	public Login(){
	
		GridBagLayout grid = new GridBagLayout();
		setLayout(grid);
		
		//plass til evt logo
		GridBagConstraints topG = new GridBagConstraints();
		topG.gridwidth = 4;
		topG.gridx = 0;
		topG.gridy = 0;
		icon = new ImageIcon("img/logo.png");
		//top.setBounds(5, 200, 150, 150);
      	top = new JLabel();
      	top.setIcon(icon);
		add(top);
		grid.setConstraints(top, topG);
		
		
		//Brukernavn Label
		GridBagConstraints nameL = new GridBagConstraints();
        nameL.gridx = 0;
        nameL.gridy = 1;
		brukernavn = new JLabel("Brukernavn: ");
		add(brukernavn);
		grid.setConstraints(brukernavn, nameL);
		
		//Brukernavn tekstfelt
		GridBagConstraints nameT = new GridBagConstraints();
		nameT.gridwidth = 2;
        nameT.gridx = 1;
        nameT.gridy = 1;
		usernametext = new JTextField(15);
		usernametext.setName("username");
		usernametext.addKeyListener(new usernameListener());
		add(usernametext);
		grid.setConstraints(usernametext, nameT);
		
		
		
		
		//Passord label
		GridBagConstraints passL = new GridBagConstraints();
        passL.gridx = 0;
        passL.gridy = 2;
		passord = new JLabel("Passord: ");
		add(passord);
		grid.setConstraints(passord, passL);
		
		//passord tekstfelt
		GridBagConstraints passF = new GridBagConstraints();
		passF.gridwidth = 2;
        passF.gridx = 1;
        passF.gridy = 2;
		passwordfield = new JPasswordField(15);
		passwordfield.setName("password");
		passwordfield.addKeyListener(new passwordListener());
		add(passwordfield);
		grid.setConstraints(passwordfield, passF);
		
		
		//Space label
		GridBagConstraints spaceG = new GridBagConstraints();
        spaceG.gridx = 0;
        spaceG.gridy = 3;
        space = new JLabel(" ");
        add(space);
        grid.setConstraints(space, spaceG);
        
		
	
		
		//Logg inn knapp
		GridBagConstraints logB = new GridBagConstraints();
		logB.gridx = 1;
        logB.gridy = 4;
		login = new JButton("Logg inn");
		login.addActionListener(new loginListener());
		add(login);
		grid.setConstraints(login, logB);
		
		
		
		//Avbryt knapp
		GridBagConstraints canB = new GridBagConstraints();
		canB.gridx = 2;
        canB.gridy = 4;
		cancel = new JButton("Avbryt");
		cancel.addActionListener(new cancelListener());
		add(cancel);
		grid.setConstraints(cancel, canB);

	}
	
	class usernameListener implements KeyListener{
		public void keyPressed(KeyEvent arg0) {
			
		}
		public void keyReleased(KeyEvent e) {
			
		}
		public void keyTyped(KeyEvent e) {
			
		}	
	}
	
	class passwordListener implements KeyListener{
		public void keyPressed(KeyEvent arg0) {
			
		}
		public void keyReleased(KeyEvent e) {
			
		}
		public void keyTyped(KeyEvent e) {
			
		}	
	}
	
	class loginListener implements ActionListener{
		public void actionPerformed(ActionEvent arg0) {
				
		}	
	}
	
	class cancelListener implements ActionListener{
		public void actionPerformed(ActionEvent arg0) {
			System.exit(0);		
		}	
	}
	
	


	public static void main(String[] args){
			JFrame frame = new JFrame("login");
			frame.setSize(400,300);
			frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			frame.setContentPane(new Login());
			frame.setVisible(true);
			
			
	}

}
